//驳回弹窗
import React from 'react'
import { Modal, Form, Input, Button, Space, message } from "antd";
import { sharerExamine } from '@/request/distribution/sharerManagement.js'
const { TextArea } = Input

export default class RejectModal extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      isRejectModal: false, //弹窗是否打开
      sharedById: null,//用户id
      rejectBtnLoading: false, //按钮loading
    }
  }
  //打开驳回弹窗
  openRejectModal(sharedById) {
    this.setState({ isRejectModal: true, sharedById })
  }
  // 确认驳回
  rejectSubmit = async (value) => {
    let { sharedById } = this.state
    await sharerExamine({ sharedById, status: 2, ...value }).then(res => {
      if (res.code === 0) {
        message.success('驳回成功!')
        if (this.props.type === 'view') {
          this.props.history.goBack(-1)
          return
        }
        if (this.props.type === 'sharerList') {
          this.props.getRequest()
        }
      }
    })
    this.setState({ rejectBtnLoading: true })
    this.setState({ rejectBtnLoading: false, isRejectModal: false })
  }
  render() {
    let { isRejectModal, rejectBtnLoading } = this.state
    return (
      <Modal title="驳回申请" visible={isRejectModal} footer={null} destroyOnClose onCancel={() => { this.setState({ isRejectModal: false }) }}>
        <Form onFinish={this.rejectSubmit} >
          <Form.Item label="驳回原因" name="rejectMessage" rules={[{ required: true }]}  >
            <TextArea placeholder='请输入驳回原因（1-200字）' maxLength={200} autoSize={{ minRows: 6, maxRows: 6 }} showCount />
          </Form.Item>
          <Form.Item wrapperCol={{ offset: 8, span: 16 }} >
            <Space>
              <Button onClick={() => { this.setState({ isRejectModal: false }) }}>取消</Button>
              <Button type="primary" htmlType="submit" loading={rejectBtnLoading}>确定</Button>
            </Space>
          </Form.Item>
        </Form>
      </Modal >
    )
  }
}